#include "thqueue.h"

pktqueue		push(AVPacket			*x,
			     pktqueue			q)
{
  pktqueue		new;

  new = malloc(sizeof(struct _pktqueue));
  new->pack = x;

  if (q)
  {
    new->next = q->next;
    q->next = new;
    new->num = (q->num + 1);
  }

  else
  {
    new->next = new;
    new->num = 1;
  }

  return (new);
}


AVPacket		*pull(pktqueue			*q)
{
  pktqueue		older;
  AVPacket		*old = NULL;

  if (*q)
  {
    older = (*q)->next;

    if (older && (older != *q))
    {
      old = older->pack;
      (*q)->next = older->next;
      free(older);
    }

    else
    {
      old = (*q)->pack;
      free(*q);
      *q = NULL;
    }
  }

  return (old);
}

int			q_empty(pktqueue		q)
{
  if (q)
    return 0;
  else
    return 1;
}

int			q_num(pktqueue			q)
{
  if (q)
    return (q->num);
  else
    return 0;
}
